home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Ham⁄GPS / SoftKiss.src.1.8 Folder / SoftKiss.src.1.8 / core / sfk_core_control.c < prev    next >
Text File  |  1993-03-13  |  2KB  |  111 lines

  1. /*
  2.  * SoftKiss dispatch for control calls
  3.  * by Aaron Wohl / N3LIW (aw0g+@andrew.cmu.edu) jul 1990
  4.  * 6393 Penn Ave #303
  5.  * Pittsburgh PA, 15206
  6.  * work: (412)-268-5032
  7.  * home: (412)-731-6159
  8.  */
  9.  
  10. #include "sfk_core.h"
  11. #include "sfk_core_private.h"
  12. #include "driver_shell.h"
  13.  
  14. static char inited=FALSE;
  15.  
  16. /*
  17.  * is one time startup init done
  18.  */
  19. int sfk_init_done(void)
  20. {
  21.     return inited;
  22. }
  23.  
  24. /*
  25.  * a control call to the us has failed
  26.  * unwind the stack and return the error
  27.  */
  28. void sfk_control_fail(sfk_iio_pt iicmd,short io_err,short iio_err)
  29. {
  30.     if(io_err==0)io_err= -1;
  31.     if(iio_err==0)iio_err= 1;
  32.     if((iicmd->uio!=0)&&(iicmd->uio->csCode>=sfk_CMD_base)) {
  33.         iicmd->uio->do_this.sfk_hdr.sys_err_code=io_err;
  34.         iicmd->uio->do_this.sfk_hdr.sfk_err_code=iio_err;
  35.     }
  36.     longjmp(iicmd->err_throw,1);
  37. }
  38.  
  39. /*
  40.  * dispatch to handle opening the driver
  41.  */
  42. int sfk_init(void)
  43. {
  44.     sfk_io_record cmd;
  45.     sfk_INIT_CPB(cmd,0,sfk_CMD_run);
  46.     sfk_control(&cmd);
  47.     if(inited)
  48.         return noErr;
  49.     return -ioErr;
  50. }
  51.  
  52. /*
  53.  * dispatch to handle closing the driver
  54.  */
  55. int sfk_uninit(sfk_io_record_pt pb)
  56. {
  57.     sfk_io_record cmd;
  58.     char out_buf[20];
  59.     char *cmd_text=SFK_TEXT(57);
  60.     sfk_INIT_CPB(cmd,0,sfk_CMD_msg);
  61.     sfk_parse_from(&cmd,cmd_text,strlen(cmd_text),out_buf,sizeof(out_buf),0);
  62.     sfk_control(&cmd);
  63.     return noErr;
  64. }
  65.  
  66. /*
  67.  * dispatch to handle a control call depending on command chosen
  68.  */
  69. int sfk_control(sfk_io_record_pt pb)
  70. {
  71.     sfk_iio cmd;
  72.     cmd.uio=pb;
  73.     if(pb->csCode>=sfk_CMD_base) {
  74.         pb->do_this.sfk_hdr.sys_err_code=0;
  75.         pb->do_this.sfk_hdr.sfk_err_code=0;
  76.     }
  77.     if(setjmp(cmd.err_throw)!=0)
  78.         return ioErr;
  79.  
  80.     if(!inited)
  81.         sfk_init_commands(&cmd);
  82.     inited=TRUE;
  83.  
  84.     switch(pb->csCode) {
  85.         case sfk_CMD_run:
  86.             sfk_tick(&cmd);
  87.             break;
  88.         case sfk_CMD_attach:
  89.             sfk_control_fail(&cmd,0,sfk_NOT_YET_IMPLEMENTED);
  90.             break;
  91.         case sfk_CMD_detach:
  92.             sfk_control_fail(&cmd,0,sfk_NOT_YET_IMPLEMENTED);
  93.             break;
  94.         case sfk_CMD_msg:
  95.             sfk_parse_command(&cmd);
  96.             break;
  97.         case sfk_CMD_write:
  98.             sfk_write(&cmd);
  99.             break;
  100.         case sfk_CMD_read:
  101.             sfk_read(&cmd);
  102.             break;
  103.         case sfk_CMD_goodbye:
  104.         case sfk_CMD_killio:
  105.             break;
  106.         default:
  107.                 return -17;        /*don't like this control call*/            
  108.     }
  109.     return noErr;
  110. }
  111.